package com.riant.demo.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Classname MyMetaObjectHandler
 * @Description TODO
 * @Date 2021/7/2 0:07
 * @Created by 张斌
 */
@Slf4j
@Component//一定把处理器加到IOC容器中
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * 插入时填充策略
     * */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("插入时填充");
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);

    }
    /**
     * 更新时填充策略
     * */
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("更新时填充");
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
